﻿<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"  %>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.util.Enumeration, java.util.*, java.text.* "%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

<%
	Connection con = null;
	Statement stmt = null;
	ResultSet rs = null;
	
	Class.forName("com.mysql.jdbc.Driver"); 		//jdbc driver load
	String url = "jdbc:mysql://localhost:3306/mydb";	//connect db
	String id = "son";
	String password = "0302";

try {
	con = DriverManager.getConnection(url, id, password);
	stmt = con.createStatement(); 			//to make the Statement for SQL

	String tempId = request.getParameter("registId");
	String tempEmail = request.getParameter("registEmail");
	String tempName = request.getParameter("registName");
	String tempRegist = request.getParameter("regist");
	String tempSession = (String) session.getAttribute("session_id");
	
	
	int updateCount = 0;
	
	//ID or Password 에 null 값이 입력될 경우 (처리 x)
	if (tempId == null || tempName == null) {
    //     response.sendRedirect("login.jsp");
    }
    
    StringBuilder sb = new StringBuilder();
    
    sb.append("INSERT INTO mydb.members \n");
    sb.append("       ( email, member_id, member_name, update_time, user_id ) \n");
    sb.append("VALUES ( '" + tempEmail + "', '" + tempId + "', '" + tempName + "', now(), '" + tempSession +  "')");
    
    System.out.println("query = "+ sb.toString());
    updateCount = stmt.executeUpdate(sb.toString());
    
    
    if (updateCount > 0) { 
%>
	    <script type="text/javascript">
	    	//alert("성공");
	    	//location.href="main.jsp";
	    	window.setTimeout('alert("성공")', 1000);
	    </script>	
    <% 
    
    } else {
    %>
	    <script type="text/javascript">
	    	window.setTimeout('alert("성공")', 1000);
	    	//alert("실패");
	    	//location.href="main.jsp";
	    </script>	
    <% 	
    }
	%>    

<%
} catch(Exception e) {
    e.printStackTrace();
    throw e;
} finally {
    if (rs   != null)
        try { rs.close(); } catch(Exception e) {};	//JDBC 객체 연결 해제
    if (stmt != null)
        try { stmt.close(); } catch(Exception e) {};
    if (con  != null)
        try { con.close(); } catch(Exception e) {};
    response.sendRedirect("main.jsp");
}
%>
</body>
</html>